// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import VueRouter from 'vue-router'
import $ from 'jquery'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios';


axios.defaults.baseURL = "http://localhost:8090";

axios.interceptors.request.use(config=>{

  if(localStorage.getItem("token")!=null){
    config.headers.token = localStorage.getItem("token");
  }
  return config
})

axios.interceptors.response.use(config=>{
  if(config.headers.token!=null){
    localStorage.setItem("token",config.headers.token)
  }
  return config
})



Vue.prototype.$http = axios;
Vue.use(ElementUI);

Vue.use(VueRouter);


const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}




Vue.config.productionTip = false;
Vue.prototype.$=$;


// router.beforeEach((to, from, next) => {
//   if (to.path == "/login" || to.path == "/" || to.path == "/register" || to.path == "/noaccess") {
//     next()
//   } else {
//     let roleId = JSON.parse(localStorage.getItem("loginUser"))
//     if (roleId == null) {
//       next("/login")
//     } else {
//       if (to.path == "/main" || to.path == "/car" || to.path == "/learn" || to.path == "/rental" || to.path ==
//         "/notice") {
//         if (roleId.roleIds[0] != 5) {
//           next()
//         } else {
//           next("/noaccess")
//         }
//       } else {
//         if (roleId.roleIds[0] == 5) {
//           next()
//         } else {
//           next("/noaccess")
//         }
//       }
//     }

//   }
// })


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
